#!/bin/bash
# author = Remco Brink <remco@rc6.org>

# Log
LOGFILE=/home/flow/bin/logs/load_kill_log

# log the process causing the load at the time.
PSFILE=/home/flow/bin/logs/ps_log

# Obtain the server load
loadavg=`uptime |cut -d , -f 4|cut -d : -f 2`
thisloadavg=`echo $loadavg|awk -F \. '{print $1}'`

if [ "$thisloadavg" -ge "10" ]; then

# Output to logfiles
ps auxfww >> $PSFILE
date >> $LOGFILE

# Output some status message
echo "High load detected!"

# Send mail
echo "Load is high on the server" | mail -s "Loadspike" nilicule@gmail.com

# Issue the command of choice.  This can be any shell command.
/usr/bin/sudo killall -9 lighttpd

fi
